

<% if flash[:notice] %>
    <div id="notice"><%= flash[:notice] %></div>
<% end %>

<%@title_view = 'Catálogo'%>

<% form_tag url_for(:action=>"discovery_search"),{:id =>"users_form_search"} do -%>
  <div class="shadow" style="width: 878px; float:left;">
    <fieldset id="agrupacion">
      <legend>Criterios</legend>

      <fieldset class="column-left">
        <p>
          <label><b>Tipología</b></label>
          <%if @active_tipology%>
            <%= select_tag "tipology", options_for_select((CulturalHeritage::Tipology.find(:all,:conditions=>{:deleted=>[0]})).sort!{|a,b| a.name.downcase <=> b.name.downcase}.collect { |t| [t.name,t.id]}),:include_blank=>"Seleccione", :class=>"", :onchange=>"document.getElementById('page_number').value = '1', document.forms['users_form_search'].submit()" %>
          <%else%>
            <label style="font-weight: lighter"><%=(CulturalHeritage::Tipology.find(:all,:conditions=>{:deleted=>[0], :id=>@tipology})).at(0).name%></label>
            <%= select_tag "tipology", options_for_select((CulturalHeritage::Tipology.find(:all,:conditions=>{:deleted=>[0], :id=>@tipology})).collect { |t| [t.name,t.id]}), :class=>"", :style=>"display:none"%>
          <%end%>
        </p>

        <p>
          <label><b>Periodo</b></label>
          <%if @active_period%>
            <%= select_tag "period", options_for_select((CulturalHeritage::Period.find(:all,:conditions=>{:deleted=>[0]})).sort!{|a,b| a.name.downcase <=> b.name.downcase}.collect { |t| [t.name,t.id]}),:include_blank=>"Seleccione", :class=>"", :onchange=>"document.getElementById('page_number').value = '1'; document.forms['users_form_search'].submit()" %>
          <%else%>
            <label style="font-weight: lighter"><%=(CulturalHeritage::Period.find(:all,:conditions=>{:deleted=>[0], :id=>@period})).at(0).name%></label>
            <%= select_tag "period", options_for_select((CulturalHeritage::Period.find(:all,:conditions=>{:deleted=>[0], :id=>@period})).collect { |t| [t.name,t.id]}), :class=>"", :style=>"display:none"%>
          <%end%>
        </p>

        <br />
        <input type="submit" onclick="document.getElementById('tipology').options.length = 0;
          document.getElementById('period').options.length = 0;
          document.getElementById('culture').options.length = 0;
          document.getElementById('cultural_institution').options.length = 0;
          document.getElementById('fields_order').value = '';
          document.forms['users_form_search'].submit()" style="float: center; margin: 0px" value="Reiniciar"/>

      </fieldset>

      <fieldset class="column-right">

        <p>
          <label><b>Cultura</b></label>
          <%if @active_culture%>
            <%= select_tag "culture", options_for_select((CulturalHeritage::Culture.find(:all,:conditions=>{:deleted=>[0]})).sort!{|a,b| a.name.downcase <=> b.name.downcase}.collect { |t| [t.name,t.id]}),:include_blank=>"Seleccione", :class=>"", :onchange=>"document.getElementById('page_number').value = '1'; document.forms['users_form_search'].submit()" %>
          <%else%>
            <label style="font-weight: lighter"><%=(CulturalHeritage::Culture.find(:all,:conditions=>{:deleted=>[0], :id=>@culture})).at(0).name%></label>
            <%= select_tag "culture", options_for_select((CulturalHeritage::Culture.find(:all,:conditions=>{:deleted=>[0], :id=>@culture})).collect { |t| [t.name,t.id]}), :class=>"", :style=>"display:none"%>
          <%end%>
        </p>


        <p>
          <label><b>Institución cultural</b></label>
          <%if @active_cultural_institution%>
            <%= select_tag "cultural_institution", options_for_select((CulturalHeritage::CulturalInstitution.find(:all,:conditions=>{:deleted=>[0]})).collect { |t| [t.name,t.id]}),:include_blank=>"Seleccione", :class=>"", :onchange=>"document.getElementById('page_number').value = '1'; document.forms['users_form_search'].submit()" %>
          <%else%>
            <label style="font-weight: lighter"><%=(CulturalHeritage::CulturalInstitution.find(:all,:conditions=>{:deleted=>[0], :id=>@cultural_institution})).at(0).name%></label>
            <%= select_tag "cultural_institution", options_for_select((CulturalHeritage::CulturalInstitution.find(:all,:conditions=>{:deleted=>[0], :id=>@cultural_institution})).collect { |t| [t.name,t.id]}), :class=>"", :style=>"display:none"%>
          <%end%>

        </p>



      </fieldset>
    </fieldset>
  </div>
  <%=  hidden_field_tag 'page_number', @page_number%>
  <%=  hidden_field_tag 'fields_order', @order%>
<% end %>

<div class="shadow" style="width: 162px; height: 675px; float:left; -moz-border-radius: 10px; margin-right: 10px; padding: 10px">

  <%routes = @order.split(", ")%>
  <%l = 1%>
  <%routes.each do |rout|%>
    <%if (l == 1)%>
      <b><%=rout%><br /><br /></b>
      <%l= 0%>
    <%else%>
        <%=rout%><br /><br />
        <%l= 1%>
      <%end%>
    <%end%>

  <b>Total de coincidencias</b> <br/> <br/> <%=@total_registers%> <br/> <br/>  
</div>

<div class="shadow" style="width: 704px; height: 695px; float:right; -moz-border-radius: 10px; padding: 0px">

  <%i = 0%>
  <%@cultural_heritage_cultural_heritages.each do |cultural_heritage|%>
    <%if i < 6%>
      <div style="width: 330px; height: 200px; border-width: 1px; border-style: solid; float:left; margin: 10px;">
        <div style="width: 150px; height: 188px; float:left; margin: 0px 0px 0px 0px; padding: 5px; -moz-border-radius: 10px; text-align: justify">
          <%if cultural_heritage.name.length < 51%>
            <%if cultural_heritage.group == 1%>
              <b><%= link_to cultural_heritage.name, {:controller=>"/cultural_heritage/cultural_heritages",:action => 'show',:id => cultural_heritage.id}%></b><br/>
            <%else%>
              <b><%= link_to cultural_heritage.name, {:controller=>"/cultural_heritage/cultural_heritage_properties",:action => 'show',:id => cultural_heritage.id}%></b><br/>
            <%end%>
          <%else%>
            <%if cultural_heritage.group == 1%>
              <b><%= link_to (cultural_heritage.name[0..50] << "..."), {:controller=>"/cultural_heritage/cultural_heritages",:action => 'show',:id => cultural_heritage.id}, {:title => cultural_heritage.name}%></b><br/>
            <%else%>
              <b><%= link_to (cultural_heritage.name[0..50] << "..."), {:controller=>"/cultural_heritage/cultural_heritage_properties",:action => 'show',:id => cultural_heritage.id}, {:title => cultural_heritage.name}%></b><br/>
            <%end%>
          <%end%>
          <br />
          <%if cultural_heritage.description.length < 200%>
            <%=cultural_heritage.description%>
          <%else%>
            <%=cultural_heritage.description[0..200] << "..."%>
          <%end%>
        </div>
        <div style="width: 150px; height: 188px; border-width: 1px; border-style: none; float:right; margin: 0px 0px 0px 0px; padding: 5px; text-align: center">
          <%if (cultural_heritage.avatar.url.blank? || cultural_heritage.avatar_file_name.blank?)%>
            <img src="<%= root_url %>images/pukara_logo.png" alt="Imagen" title="<%=cultural_heritage.name%>" style="padding: 0px; height: 185px; border-style: none"/>
          <%else%>
            <a href="<%=cultural_heritage.avatar.url%>" rel="lightbox[roadtrip]"> <img src="<%=cultural_heritage.avatar.url%>" alt="Imagen" title="<%=cultural_heritage.name%>" style="padding: 0px; height: 185px; width: 130px; border-style: none"/></a>
          <%end%>
        </div>
      </div>
      <%i= i +1%>
    <%end%>
  <%end%>
  <div style="width: 692px; text-align: right; float:left; heigth: 20px">
    <%if !(@cultural_heritage_cultural_heritages.length == 0)%>
      <label class="non_hover_label" style="width: 55px">Página</label>
      <%@pages.each do |page|%>
        <%if page.eql?(@page_number.to_s)%>
          <label class="non_hover_label"><b><%=page%> </b></label>
        <%else%>
          <label class="hover_label"onclick="document.getElementById('page_number').value = <%=page%>; document.forms['users_form_search'].submit()"><%=page%></label>
        <%end%>
      <%end%>
    <%else%>
      <label style="width: 600px; margin-top: 10px; margin-left: 10px; float: left; text-align: left">No se encontraron registros de acuerdo a los criterios indicados.</label>
    <%end%>

  </div>
</div>

<div class="shadow" style="width: 850px; float:left; padding-left: 40px; padding-top: 10px">

  <%= stylesheet_link_tag 'gmaps4rails' %>
  <h3>Ubicación</h3>
  <div style="float: right; width: 220px; overflow-y: auto; height: 414px"><ul id="markers_list">  </ul></div>
  <%= gmaps({
      "map_options" => { "type" => "HYBRID", "center_longitude" => 180, "zoom" => 4, "auto_adjust" => true},
      "markers"     => { "data" => @json, "options" => {"list_container" => "markers_list" } }
    })
%>
</div>






